package AST;

public class WhileStmt extends CompoundStmt {
	private Test whileTest;
	private Suite whileSuite;
	private Suite elseSuite;

	public WhileStmt(Test whileTest, Suite whileSuite, Suite elseSuite) {
		print();
		this.whileTest = whileTest;
		this.whileSuite = whileSuite;
		this.elseSuite = elseSuite;
	}

	public WhileStmt() {
		print();
	}

	public Test getWhileTest() {
		return whileTest;
	}

	public void setWhileTest(Test whileTest) {
		this.whileTest = whileTest;
	}

	public Suite getWhileSuite() {
		return whileSuite;
	}

	public void setWhileSuite(Suite whileSuite) {
		this.whileSuite = whileSuite;
	}

	public Suite getElseSuite() {
		return elseSuite;
	}

	public void setElseSuite(Suite elseSuite) {
		this.elseSuite = elseSuite;
	}

	public void print() {
		System.out.println("WhileStmt");
	}

	public void genC(PW pw) {

		if (elseSuite == null) {
			pw.print("while( ");
			whileTest.genC(pw);
			pw.print(" )");
			whileSuite.genC(pw);
		} else {
			pw.print("if ( ");
			whileTest.genC(pw);
			pw.print(") {\n");
			pw.print("\twhile( ");
			whileTest.genC(pw);
			pw.print(" )");
			whileSuite.genC(pw);
			pw.print("} else {\n");
			pw.print("\t if ( elseFlag == 1 )\n");
			elseSuite.genC(pw);
			pw.print("}");
		}

	}
}
